/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.anproc.registery;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author User
 */
public class SingletonItemDescriptor extends RegisteredItemDescriptor {

    private Object item = null;
    private String itemClass = null;

    @Override
    public Object createItem() {
        if (item == null) {
            try {
                item = Thread.currentThread().getContextClassLoader().loadClass(itemClass).newInstance();
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
                throw new RuntimeException(ex.getCause() == null ? ex : ex.getCause());
            }
        }

        return item;
    }

    public SingletonItemDescriptor setItemClass(String itemClass) {
        this.itemClass = itemClass;
        return this;
    }

    public String getItemClassName() {
        return itemClass;
    }

    @Override
    public SingletonItemDescriptor setDescription(String description) {
        return (SingletonItemDescriptor) super.setDescription(description); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public SingletonItemDescriptor setIconPath(String iconPath) {
        return (SingletonItemDescriptor) super.setIconPath(iconPath); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public SingletonItemDescriptor setName(String name) {
        return (SingletonItemDescriptor) super.setName(name); //To change body of generated methods, choose Tools | Templates.
    }
}
